﻿// Example header text. Can be configured in the options.
using System;
using System.Data;
using System.Data.SqlClient;
using vtech_frameWorks.DAO;
using vtech_frameWorks.Exceptions;
using vtech_frameWorks.Object;

namespace vtech_system.Role
{
    public class ClsRoleDAO : ClsObjectDAO
    {
        #region "Get All"
        /****** 
        * =============================================
        * Author:		<chaunn>
        * Create date: <10.03.2011>
        * Good
        * Description:	Lấy tất cả Role
        * =============================================
        * ******/
        /// <summary>
        /// Lấy tất cả Role
        /// </summary>
        /// <param name="sqlTransaction"></param>
        /// <returns></returns>
        public override DataTable GetAll(SqlTransaction sqlTransaction)
        {
            try
            {
                return ClsBaseDbAccessDAO.ExecuteSqlDataAdapter(sqlTransaction, "spGetRole").Tables[0];
            }
            catch (Exception ex)
            {
                ClsInformation.Error(ex.Message);
                return null;
            }
        }

        #endregion

        #region "Insert"
        /****** 
        * =============================================
        * Author:		<chaunn>
        * Create date: <10.03.2011>
        * Good
        * Description:	Thêm mới Role
        * =============================================
        * ******/
        /// <summary>
        /// Thêm mới user
        /// </summary>
        /// <param name="sqlTran"></param>
        /// <param name="dRow"></param>
        public override void Insert(SqlTransaction sqlTran, DataRow dRow)
        {
            try
            {
                SqlParameter[] paramArray = new SqlParameter[]
                {
                    ClsBaseDbAccessDAO.CreateSqlPrameter("@ID", SqlDbType.UniqueIdentifier, 1, ParameterDirection.Input),
                    ClsBaseDbAccessDAO.CreateSqlPrameter("@Code", SqlDbType.NVarChar, 50, ParameterDirection.Input),
                    ClsBaseDbAccessDAO.CreateSqlPrameter("@Name", SqlDbType.NVarChar, 255, ParameterDirection.Input),
                    ClsBaseDbAccessDAO.CreateSqlPrameter("@Description", SqlDbType.NVarChar, 255, ParameterDirection.Input),
                    ClsBaseDbAccessDAO.CreateSqlPrameter("@Inactive", SqlDbType.Bit, 1, ParameterDirection.Input)
                };
                ClsBaseDbAccessDAO.SetParameterValues(paramArray, dRow);
                ClsBaseDbAccessDAO.ExecuteProcedure(sqlTran, "spAddRole", paramArray);
            }
            catch (Exception ex)
            {
                ClsInformation.Information(ex.Message);
                return;
            }
        }

        #endregion

        #region "Edit"
        /****** 
        * =============================================
        * Author:		<chaunn>
        * Create date: <10.03.2011>
        * Good
        * Description:	Edit Role
        * =============================================
        * ******/
        /// <summary>
        /// Edit user
        /// </summary>
        /// <param name="dRow"></param>
        public override void Edit(SqlTransaction sqlTran, DataRow dRow)
        {
            try
            {
                SqlParameter[] paramArray = new SqlParameter[]
                {
                    ClsBaseDbAccessDAO.CreateSqlPrameter("@ID", SqlDbType.UniqueIdentifier, 1, ParameterDirection.Input),
                    ClsBaseDbAccessDAO.CreateSqlPrameter("@Code", SqlDbType.NVarChar, 50, ParameterDirection.Input),
                    ClsBaseDbAccessDAO.CreateSqlPrameter("@Name", SqlDbType.NVarChar, 255, ParameterDirection.Input),
                    ClsBaseDbAccessDAO.CreateSqlPrameter("@Description", SqlDbType.NVarChar, 255, ParameterDirection.Input),
                    ClsBaseDbAccessDAO.CreateSqlPrameter("@Inactive", SqlDbType.Bit, 1, ParameterDirection.Input)
                };
                ClsBaseDbAccessDAO.SetParameterValues(paramArray, dRow);
                ClsBaseDbAccessDAO.ExecuteProcedure(sqlTran, "spEditRole", paramArray);
            }
            catch (Exception ex)
            {
                ClsInformation.Error(ex.Message);
                return;
            }
        }

        #endregion

        #region "Delete"
        /****** 
        * =============================================
        * Author:		<chaunn>
        * Create date: <10.03.2011>
        * Good
        * Description:	Xóa Role
        * =============================================
        * ******/
        /// <summary>
        /// Xóa user
        /// </summary>
        /// <param name="dataRow"></param>
        public override void Delete(SqlTransaction sqlTransaction, DataRow dataRow)
        {
            try
            {
                SqlParameter[] paramArray = new SqlParameter[]
                {
                    ClsBaseDbAccessDAO.CreateSqlPrameter("@ID", SqlDbType.UniqueIdentifier, 1, ParameterDirection.Input),
                };
                ClsBaseDbAccessDAO.SetParameterValues(paramArray, dataRow);

                ClsBaseDbAccessDAO.ExecuteNonQuery(sqlTransaction, "DELETE FROM [tblRole] WHERE [ID] = @ID", paramArray);
            }
            catch (Exception ex)
            {
                ClsInformation.Error(ex.Message);
            }
        }
        #endregion
    }
}